package com.ruoyi.meeting.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.meeting.domain.TmdMeetingManager;
import com.ruoyi.meeting.service.ITmdMeetingManagerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议室管理Controller
 * 
 * @author hdy
 * @date 2024-04-19
 */
@Controller
@RequestMapping("/meeting/manager")
public class TmdMeetingManagerController extends BaseController
{
    private String prefix = "meeting/manager";

    @Autowired
    private ITmdMeetingManagerService tmdMeetingManagerService;

    @RequiresPermissions("meeting:manager:view")
    @GetMapping()
    public String manager()
    {
        return prefix + "/manager";
    }

    /**
     * 查询会议室管理列表
     */
    @RequiresPermissions("meeting:manager:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TmdMeetingManager tmdMeetingManager)
    {
        startPage();
        List<TmdMeetingManager> list = tmdMeetingManagerService.selectTmdMeetingManagerList(tmdMeetingManager);
        return getDataTable(list);
    }

    /**
     * 导出会议室管理列表
     */
    @RequiresPermissions("meeting:manager:export")
    @Log(title = "会议室管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TmdMeetingManager tmdMeetingManager)
    {
        List<TmdMeetingManager> list = tmdMeetingManagerService.selectTmdMeetingManagerList(tmdMeetingManager);
        ExcelUtil<TmdMeetingManager> util = new ExcelUtil<TmdMeetingManager>(TmdMeetingManager.class);
        return util.exportExcel(list, "会议室管理数据");
    }

    /**
     * 新增会议室管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存会议室管理
     */
    @RequiresPermissions("meeting:manager:add")
    @Log(title = "会议室管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TmdMeetingManager tmdMeetingManager)
    {
        return toAjax(tmdMeetingManagerService.insertTmdMeetingManager(tmdMeetingManager));
    }

    /**
     * 修改会议室管理
     */
    @RequiresPermissions("meeting:manager:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TmdMeetingManager tmdMeetingManager = tmdMeetingManagerService.selectTmdMeetingManagerById(id);
        mmap.put("tmdMeetingManager", tmdMeetingManager);
        return prefix + "/edit";
    }

    /**
     * 修改保存会议室管理
     */
    @RequiresPermissions("meeting:manager:edit")
    @Log(title = "会议室管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TmdMeetingManager tmdMeetingManager)
    {
        return toAjax(tmdMeetingManagerService.updateTmdMeetingManager(tmdMeetingManager));
    }

    /**
     * 删除会议室管理
     */
    @RequiresPermissions("meeting:manager:remove")
    @Log(title = "会议室管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tmdMeetingManagerService.deleteTmdMeetingManagerByIds(ids));
    }

//    @RequestMapping("/detail/{id}")
//    @ResponseBody
//    public AjaxResult detail(Long id, ModelMap mmap){
//        //通过传入的id 查询现在的id对应的会议室管理信息
//        TmdMeetingManager tmdMeetingManager = tmdMeetingManagerService.selectTmdMeetingManagerById(id);
//        AjaxResult ajaxResult;
//        if(tmdMeetingManager!= null){
//            //将会议室管理信息放入到modelMap中
//            mmap.put("tmdMeetingManager", tmdMeetingManager);
//            //返回成功信息
//            ajaxResult = AjaxResult.success();
//        }else{
//            //返回失败信息
//            ajaxResult = AjaxResult.error("会议室管理不存在");
//        }
//        return ajaxResult;
//    }

    /**
     *  change by hdy 2024-04-20
     *   查看会议室管理详情页面
     *   @RequiresPermissions: 是shiro权限验证的一个注解,权限注解，用来限制用户对特定操作进行权限访问
     *   只有登录用户有meeting:manager:detail权限才可以访问
     *   在一些基于角色的访问控制系统中，@RequiresPermissions 可以指示应用程序在执行方法之前验证当前用户是否具有指定的权限。
     *   如果当前用户未被授权执行相关操作，将抛出相关的授权异常，并且相应的操作将被拒绝执行。
     * */
    @RequiresPermissions("meeting:manager:detail")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap)
    {
        TmdMeetingManager tmdMeetingManager = tmdMeetingManagerService.selectTmdMeetingManagerById(id);
        mmap.put("tmdMeetingManager", tmdMeetingManager);
        return prefix + "/detail";
    }
}
